﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>编辑摄像头</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../static/js/common.js" charset="utf-8"></script>
</head>

<body>
    <div class="weadmin-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="we-red">*</span>摄像头名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="CameraName" name="CameraName" required="" lay-verify="required" maxlength="25"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="we-red">*</span>摄像头IP
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="CameraIP" name="CameraIP" required=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="we-red">*</span>摄像头MAC
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="CameraMac" name="CameraMac" required=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="we-red">*</span>摄像头地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="CameraAddress" name="CameraAddress" required=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="we-red">*</span>摄像头内部通道号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="ChanelID" name="ChanelID" required=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="we-red">*</span>所在教室
                </label>
                <div class="layui-input-inline">
                    <select id="CRName" name="CRName" lay-filter="CRName">
                        <option value=""></option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="we-red">*</span>此项必须唯一
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
            </div>
        </form>
    </div>


    <script type="text/javascript">
        var deptList = [];//部门列表
        var cuurentDeptId = 0;//当前部门id
        var classRoom = [];//教室列表
        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            function formRenderSelect() {
                form.render('select');
            }
            //读取教室数据
            function GetRoom(DeptID,CRID) {
                $.ajax({
                    url: ApiUrl + "TrainClassRoom/Sel",
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { '': JSON.stringify(DeptID) },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            for (var i = 0; i < data.Data.length; i++) {
                                var item = data.Data[i];
                                classRoom.push({ id: item.CRID, name: item.CRName });
                            }
                            GetSelectList(classRoom, $("#CRName"), formRenderSelect);
                            SetselectValue($("#CRName"), Number(CRID), formRenderSelect);
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }

            loaddata();
            CRID = getUrlParam("CRID")
                $.ajax({
                    url: ApiUrl + "Dep/DeptLevel",//SelTree
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            cuurentDeptId = data.Data.cuurentDeptId;
                            console.log("部门id");
                            console.log(cuurentDeptId);
                            GetRoom(cuurentDeptId, CRID);
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            

            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            });

            function loaddata() {
               var CameraID = getUrlParam("CameraID");
                $("#CameraIP").val(getUrlParam("CameraIP"));
                $("#CameraMac").val(getUrlParam("CameraMac"));
                $("#CameraAddress").val(getUrlParam("CameraAddress"));
                $("#CameraName").val(getUrlParam("CameraName"));
                $("#ChanelID").val(getUrlParam("ChanelID"));
                $("#CRName").val(getUrlParam("CRID"));
            };
            //监听提交
            form.on('submit(edit)', function (data) {
               var CameraID = getUrlParam("CameraID");
                var CameraName = $("#CameraName").val();
                if (CameraName == "") {
                    layer.msg("请输入摄像头名称！");
                    return false;
                }
                var CameraIP = $("#CameraIP").val();
                if (CameraIP == "") {
                    layer.msg("请输入摄像头IP！");
                    return false;
                }
                var CameraMac = $("#CameraMac").val();
                var CameraAddress = $("#CameraAddress").val();
                if (CameraAddress == "") {
                    layer.msg("请输入摄像头地址！");
                    return false;
                }
                var ChanelID = $("#ChanelID").val();

                var CRName = $("#CRName option:selected").text();
                var CRID = $("#CRName").val();

                var postdata = {
                    'CameraID': CameraID, 'CameraName': CameraName,'CameraIP': CameraIP, 'CameraMac': CameraMac,
                    'CameraAddress': CameraAddress, 'ChanelID': ChanelID, 'CRID': CRID
                };
                //发异步，把数据提交给后台
                $.post(ApiUrl +'CameraInfo/Edit', postdata, function (data) {
                    if (data.StatusCode == 200) {
                        layer.alert("修改成功", { icon: 6 }, function (index) {
                            parent.layer.closeAll();
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                })
                return false;
            });
        });
    </script>
</body>

</html>